﻿namespace MyServer.Todo.Domain.Aggregates.TodoGroupAggregate
{
    public class Todo : Entity
    {
        private Todo()
        {

        }
        public string Name { get; private set; }
        public string Notes { get; private set; }
        public TodoStatus TodoStatus { get;private set; }
        public DateTime CreationTime { get; private set; }
        public TodoSettings Settings { get; private set; }
        public Todo(string name, string notes) : this()
        {
            GenerateId();
            Name = name;
            Notes = notes;
            TodoStatus = TodoStatus.Going;
            CreationTime = DateTime.Now;
            Settings = TodoSettings.CreateDefaultSettings();
        }

        /// <summary>
        /// 创建日待办事项
        /// </summary>
        /// <returns></returns>
        public static Todo CreateDayTodo(string name,string notes)
        {
            var todo = new Todo(name, notes);
            todo.AddToMyDay();
            return todo;
        }

        /// <summary>
        /// 创建重要待办事项
        /// </summary>
        /// <param name="name"></param>
        /// <param name="notes"></param>
        /// <returns></returns>
        public static Todo CreateImportanceTodo(string name,string notes)
        {
            var todo = new Todo(name, notes);
            todo.MakeAsImportant();
            return todo;
        }

        /// <summary>
        /// 创建计划待办事项
        /// </summary>
        /// <param name="name"></param>
        /// <param name="notes"></param>
        /// <returns></returns>
        public static Todo CreatePlanTodo(string name, string notes)
        {
            var todo = new Todo(name, notes);
            todo.DueToday();
            return todo;
        }

        /// <summary>
        /// 添加到我的一天
        /// </summary>
        public void AddToMyDay()
        {
            Settings.AddToMyDay();
        }

        /// <summary>
        /// 标记为重要
        /// </summary>
        public void MakeAsImportant()
        {
            Settings.MakeAsImportant();
        }

        /// <summary>
        /// 今天过期
        /// </summary>
        public void DueToday()
        {
            Settings.DueToday();
        }

        public Todo Copy()
        {
            var todo_copy = new Todo(this.Name, this.Notes);
            todo_copy.TodoStatus = this.TodoStatus;
            todo_copy.Settings = this.Settings.Copy();
            return todo_copy;
        }

        public void SetDoneStatus()
        {
            this.TodoStatus = TodoStatus.Done;
        }
        public void SetGoingStatus()
        {
            this.TodoStatus = TodoStatus.Going;
        }
    }
}
